package com.sysu.minsysu.zxcx;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.sysu.R;
import com.sysu.minsysu.zxcx.NewsNetwork.LinkNode;

public class BBSMain extends ListActivity{
	private static final String TAG="BBSmain";
	ArrayList<LinkNode> mLinkNodes;
	LinearLayout mLayout;
	private ImageView imgv;
	private static String type;
	
	private ListView mListView;
	
	private ArrayList<HashMap<String, Object>> listItems;   //存放文字、图片信息   
    private SimpleAdapter listItemAdapter;                  //适配器      
	
	private String[] goodBar = {
			"程序设计竞赛","BBS使用求助","Coolest",
			"逸仙书路","星座物语","硬件点滴",
			"公务员版","讲座专栏","时光流转","计算机系"
	};
	private int i = 0;
	@Override
	public void onCreate( Bundle savedInstanceState ){
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.bbsmain);
//		mLayout = (LinearLayout)findViewById(R.id.layout);	
		mListView = getListView();
		mListView.setBackgroundResource(R.drawable.background);

		mListView.setDrawingCacheEnabled(true);
		mListView.setCacheColorHint(0);
		
		mLinkNodes = NewsNetwork.getBBSgoodbrd();
		if( mLinkNodes==null ){
			Toast.makeText(this, "网络连接出错，请检查", Toast.LENGTH_SHORT).show();
			return;
		}
		Log.v(TAG, "" + mLinkNodes.size());
		initListView();
//		LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
//		for( LinkNode node : mLinkNodes ){
//			TextView tv = new TextView(this);
//			tv.setLayoutParams(layoutParams);
////			tv.setText(node.title);
//			tv.setText(goodBar[i]);
//			tv.setTag(node);
//			tv.setTextSize(30);
//			tv.setOnClickListener( new View.OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					LinkNode node = (LinkNode)v.getTag();
//					Intent intent = new Intent(BBSMain.this, ShowBBSEntry.class);
//					intent.putExtra("linknode", node);
//					startActivity(intent);
//				}
//			});
//			mLayout.addView(tv);
//			i++;
//		}
		this.setListAdapter(listItemAdapter);
	}
	
	 /**  
     * 设置适配器内容  
     */  
    private void initListView()   {   
		  listItems = new ArrayList<HashMap<String, Object>>();  
		  ;
	      for (int i = 0; i <10; i++)      
	      {   	    	  
	          HashMap<String, Object> map = new HashMap<String, Object>();      
	          map.put("ItemTitle", goodBar[i]);  
	          Log.d(TAG, goodBar[i]);
	          map.put("ItemImage", R.drawable.icon);//图片           
	          listItems.add(map); 

	      } 
	     //生成适配器的Item和动态数组对应的元素      
	     listItemAdapter = new SimpleAdapter(this,listItems,     
	    		 R.layout.pic_list,              
	           new String[] {"ItemTitle", "ItemImage"},            
	           new int[] {R.id.pic_path, R.id.img}  
	     );      
    }  
    
    @Override  
    protected void onListItemClick(ListView l, View v, int position, long id) {  
 
			LinkNode node = mLinkNodes.get(position);
			Intent intent = new Intent(BBSMain.this, ShowBBSEntry.class);
			intent.putExtra("linknode", node);
			startActivity(intent);
    }

}
